Creating an Shop API of POST cart items into DynamoDB via Postman, lambda and API Gateway using AWS
API
It stands for Application Program interface which helps in connection of two applications, computers, or between computer programs to talk to each other. It is used to access data, server software, or other applications and has been around for some time. Each time anyone uses a particular app for weather updates or good restaurants in an app API is used.
API Gateway
A fully managed service that makes developers easily create, publish, maintain, monitor, and secure APIs at any scale. API Gateway can be used to create Restful APIs and WebSocket APIs which have real-time two-way communication applications. It is a front door for applications to access data, business logic, or functionality from your backend services.
AWS Lambda
A serverless compute service which runs code as a reply to events and automatically takes care of the bottom resources. It runs code on high availability compute infrastructure and performs all the administration of the compute resources. A few examples are HTTP requests via Amazon API Gateway, changes to objects in S3, and many others.
DynamoDB
An Amazon AWS Web Services database that is fully managed, serverless, key-value NoSQL database, has high-performance applications at any scale. It has the following benefits such as built-in security, continuous backups, automated multi-region replication, in-memory caching, and data export tools
Postman
It is an API client that makes developers create, share, test, and document APIs. It allows users to create and save simple and complex HTTP/s requests along with the read responses. It can make various types of HTTP requests such as GET, POST, PUT, PATCH it can also save environments that can be used later, it can also be used to convert the API to code for various languages such as JavaScript, Python, and many more.
Refer to the below article for a better understanding
Creating a Shop API of GET items with lambda and API Gateway using AWS
Creating an Shop API of GET items with DynamoDB, lambda and API Gateway using AWS
Creating a Shop API of POST cart items with lambda and API Gateway using AWS
Demo
Search for API Gateway in the AWS Console and click build on HTTP API
Give an API Name and click next
No changes right now in the configure routes and click next
Give a name to the stage and keep the auto-deploy as the default
Review and click on create
Adding a path in the routes and click create
Choosing the POST method, entering the path, and clicking create
Go to DynamoDB and click create table
Write down a table name, partition key and choose customize settings
In Capacity mode select on-demand
Keep the rest as it is and click on create table
Go to lambda and click on create function
Click on author from scratch, give a function name, keep other things as default and click on create function
Make below changes in code source and click deploy
In the configuration tab choose permission and click edit on the execution role section
In order to attach the policy click the below link
Clicking on inline policy
Review the policy and click create policy thus the lambda can now access the DynamoDB
Going back to Routes of API Gateway click on POST and click on attach integration
In the integration target choose “lambda function”, integration target “createcart” and click create
Copy the invoke URL of API
Post the URL in Postman with "/cart". Next click body, JSON , add the below code and click send
Scroll Down to see the response
Go DynamoDB and check inside the above table created before
Checking inside the data